#

import requests
import re
from io import BytesIO
from PIL import Image
import base64
from pyzbar import pyzbar

headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3741.400 QQBrowser/10.5.3863.400'
}


def get_page(url):
    try:
        r = requests.get(url, headers=headers)
        if r.status_code == 200:
            return r.text
    except Exception as e:
        print(e)
    return ''


def get_qr(html):
    qrs = []
    matchs = re.findall('(?<=base64,)(.*)(?=" class)', html)
    if matchs:
        for m in matchs:
            data = base64.urlsafe_b64decode(m)
            img = Image.open(BytesIO(data))
            # img.show()
            data = pyzbar.decode(img, symbols=[pyzbar.ZBarSymbol.QRCODE])[0].data.decode()
            qrs.append(data)
        return qrs

if __name__ == "__main__":
    url = 'https://my.freess.info'
    html = get_page(url)
    if html:
        qrs = get_qr(html)
        if qrs:
            with open('ss.txt', 'w') as f:
                for qr in qrs:
                    f.write(qr + '\n')

